import {
  request
} from './request';
// import{ getUserInfo } from './index'
//获取验证码
export function getPhoneCode(data) {
  return request({
    url: 'sendMsg',
    method: "GET",
    data: data.data
  })
}
//跳转方法
export function jump(page,params,jumpMethods) {
  var tabList = ['index', 'garage', 'my'];
  var jumpMethods = jumpMethods ? jumpMethods : tabList.indexOf(page) == -1 ? 'navigateTo' : 'switchTab';
  var href = page ? page : 'index'
  var data = params ?  params : '';
  wx[jumpMethods]({
    url: `/pages/${href}/${href}?${decodeURIComponent(data)}`,
  });
}

//支付方法
export function pay(flag,id,goFlag,blokindex) {
  return new Promise((resolve, reason) => {
  if(flag == 1){
    request({
      url: 'order/wx/unifiedorder',
      method: "POST",
      data: {
        orderId:id
      }
    }).then(e=>{
      wx.requestPayment({
        nonceStr: e.data.nonceStr,
        package: e.data.package,
        paySign: e.data.sign,
        timeStamp: e.data.timeStamp,
        signType:e.data.signType,
        success: e => {
          wx.showToast({
            title: "支付成功",
          });
          wx.requestSubscribeMessage({
            tmplIds:['D1aAGmje7Ge3jHV1mym23ZYiBNi67zEWSH1qmU4O18c'],
            success:e=>{
              request({
                url: 'msg/pushWatchServer',
                method: "GET",
                data: {
                  code:'D1aAGmje7Ge3jHV1mym23ZYiBNi67zEWSH1qmU4O18c',
                  orderNum:id
                }
              })
            },
            
            complete:e=>{
              getUserInfo({})
              .then((res)=>{
                let identity = res.data.userInfo.identityStatus;
                if(identity != '2' && blokindex == '0'){
                  wx.showModal({
                    title: '提示',
                    content: '尊敬的用户您好，根据国家现行法律及有关政策要求，需要您配合进行实名认证（仅首次用车）',
                    cancelText:'稍后认证',
                    success(res) {
                      if (res.confirm) {
                        wx.navigateTo({
                          url: '/pages/identity/identity',
                        })
                        wx.hideLoading()
                      } else if (res.cancel) {
                        if(goFlag) wx.redirectTo({url: '/pages/orderDeatil/orderDetail?id=' + id});
                       wx.hideLoading()
                      }
                    }
                  })
                }else{
                  if(goFlag) wx.redirectTo({url: '/pages/orderDeatil/orderDetail?id=' + id});
                }
                console.log('reeqweijawdljlaskdnals')
              })
              resolve(e);
            }
          })
        },
        fail: e => {
          wx.showToast({
            title: "支付失败",
            icon: "none"
          })
          if(goFlag) wx.navigateTo({url: '/pages/orderDeatil/orderDetail?id=' + id});
        },
        complete: e => {
       
        }
      })
    })
  }else{
    request({
      url: 'top/balancePay',
      method: "POST",
      data: {
        orderNum:id
      },
      complete: e => {
        setTimeout(e=>{
          wx.hideLoading()
        },1000)
      }
    }).then(e=>{
      wx.showToast({
        title: "支付成功",
      })
      wx.requestSubscribeMessage({
        tmplIds:['D1aAGmje7Ge3jHV1mym23ZYiBNi67zEWSH1qmU4O18c'],
        success:e=>{
          request({
            url: 'msg/pushWatchServer',
            method: "GET",
            data: {
              code:'D1aAGmje7Ge3jHV1mym23ZYiBNi67zEWSH1qmU4O18c',
              orderNum:id
            }
          })
        },
        complete:e=>{
          resolve(e);
        }
      })
    }).catch(e=>{
      wx.showToast({
        title: "支付失败",
        icon: "none"
      })
      reason(e)
    })
  }
  })
}
//获取toKen
export function getTokenId(data) {
  return request({
    url: 'weChatLogin',
    method: "GET",
    data: data.data,
    complete: data.complete
  })
}

//微信统一下单接口 
export function getWechatFlag(data) {
  return 
}
// 获取用户信息
export function getUserInfo(data) {
  return request({
    url: 'mini/login',
    method: "GET",
    data: data.data
  })
}
